# coding: utf-8
from django.db import models
from django.contrib.auth.models import User

# Create your models here.
class Server(models.Model):
    hostname      = models.CharField(max_length=32, unique=True)
    ip            = models.GenericIPAddressField(unique=True)
    cpu           = models.CharField(max_length=50)
    mem           = models.CharField(max_length=50)
    disk          = models.CharField(max_length=50)
    sn            = models.CharField(max_length=32)
    idc           = models.CharField(max_length=50)
    ipinfo        = models.CharField("[{'eth0': '192.168.1.1', 'mac': ''},{'eth1': '192.168.2.1', 'mac': ''}]", max_length=255)
    product       = models.CharField(max_length=50)
    remark        = models.TextField(default='')

    def __str__(self):
        return "{} {}".format(self.hostname, self.ip)

    class Meta:
        db_table = "server"
        permissions = (
            ("view_server", "访问服务器信息"),
        )

class Department(models.Model):
    name          = models.CharField(max_length=11)

    class Meta:
        db_table = "department"

class Profile(models.Model):
    user          = models.OneToOneField(User)
    phone         = models.CharField(max_length=11)
    title         = models.CharField(max_length=32)
    department    = models.ForeignKey(Department, null=True)
    name       = models.CharField("中文名", max_length=11, null=True)

    def __str__(self):
        return "profile: {}".format(self.user.__str__())

    class Meta:
        db_table = "profile"